const {Book} = require("../../models/Books");

async function createBook (book) {
	const bookInfo = await Book.create({
        ISBN: book.isbn, 
        title: book.title,
        author: book.author,
        publisher: book.publisher,
        pubdate: book.pubdate,
        edition: book.edition,
        page: book.page,
        price: book.price,
        //内容简介
        gist: book.gist,
        img: book.img,
        //开本
        format: book.format,
        //装帧
        binding: book.binding,
        firstCategory:"",
        secondCategory:[]
	});
}

module.exports = async (req, res) => {
   var isbn = req.query.ISBN

    try{
        
    const s1 = await Book.findOne({ISBN: isbn});

    if(s1 == null){
        const ShowapiRequest = require('showapirequest_nodejs')

        //创建请求对象
        // const sdk = new ShowapiRequest(
        //   'https://route.showapi.com/1626-1',//接口地址,注意需要先订购了相关套餐才能调
        //   'appId',//替换为真实的appId
        //   'sign'//替换为真实的密钥
        // )
        
        // sdk
        //   .addTextPara("isbn",isbn)
        //   .post()//post方式发送请求，返回axios.post()的Promise
        //   .then((res) => {
            //    let s2 = Object.assign({},res.data);
            //    delete s2.produce
            //    s1 = Object.assign(s1,s2);
            //      createBook(s1);
            //    res.send({errCode:"1",msg:"请求成功",data:{book:s1}})
        //     console.info("#####result:",res.data)
        //     console.info("#######axios all response:",res)
        //   })
        //   .catch((error) => {
        //     console.error(error)
        //   })
    }else{
        res.send({errCode:"1",msg:"请求成功",data:{book:s1}})
    }
    }catch(e){
        res.status(400).send({errCode:"1",msg:"请先登录"})
    }
}